<?php

namespace ManiaLivePlugins\MLEPP\ChallengeWidget\Gui\Windows;

use ManiaLive\PluginHandler\PluginHandler;
use ManiaLib\Gui\Elements\BgsPlayerCard;
use ManiaLib\Gui\Elements\Bgs1InRace;

use ManiaLive\Gui\Windowing\Controls\Pager;
use ManiaLib\Gui\Layouts\Flow;
use ManiaLib\Gui\Elements\Quad;
use ManiaLib\Gui\Elements\Label;
use ManiaLive\Gui\Windowing\Controls\Frame;
use ManiaLive\Data\Storage;
use ManiaLive\Utilities\Time;
use ManiaLivePlugins\MLEPP\Core\Core;

class ChallengeWidgetWindow extends \ManiaLive\Gui\Windowing\Window
{
	protected $frame;
	public $nowPlaying;
	public $trackname;
	public $trackauthor;
	public $serverCountry;
	public $showinfo;
	private $tmx;
	private $background;
	public $callback;
	private $serverc;
	private $textColor = '$eee';

	function initializeComponents()
	{
            if (empty(Core::$widget_background)) {
                $this->background = new \ManiaLib\Gui\Elements\Bgs1();
		$this->background->setSubStyle("NavButton");
            } else  {
                $this->background = new Quad();
		$this->background->setImage(Core::$widget_background, true);
            }
		$this->background->setSize(50, 25);
		$this->background->setValign("center");
		$this->background->setHalign("center");
		$this->background->setPosY(0);

		$this->serverc = new Quad();
		$this->serverc->setSize(4,4);
		$this->serverc->setValign("top");
		$this->serverc->setHalign("left");
		$this->serverc->setPosY($this->posY+0.5);
		$this->serverc->setPosX($this->posX-24);

		$this->tmx = new Quad();
		$this->tmx->setImage(Core::$widget_graphics_tmx,true);
		$this->tmx->setImageFocus(Core::$widget_graphics_tmx_hover,true);
		$this->tmx->setAction($this->callback('onTmxClick'));
		$this->tmx->setSize(8, 4);
		$this->tmx->setPosition($this->posX+24,$this->posY+7.5);
		$this->tmx->setValign("top");
		$this->tmx->setHalign("right");

		$this->nowPlaying= new Label();
		$this->nowPlaying->setPosition($this->posX,$this->posY+2.5); //3.5
		$this->nowPlaying->setSize(40, 3);
		$this->nowPlaying->setValign("top");
		$this->nowPlaying->setHalign("center");
		$this->nowPlaying->setTextSize(2);

		$this->trackname= new Label();
		$this->trackname->setPosition($this->posX,$this->posY+5); // 7
		$this->trackname->setSize(40, 3);
		$this->trackname->setValign("top");
		$this->trackname->setHalign("center");
		$this->trackname->setTextSize(4);

		$this->trackauthor=new Label();
		$this->trackauthor->setPosition($this->posX,$this->posY+8.5); // 10
		$this->trackauthor->setSize(25, 3);
		$this->trackauthor->setValign("top");
		$this->trackauthor->setHalign("center");
		$this->trackauthor->setTextSize(3);

		$this->showinfo=new Label();
		$this->showinfo->setPosition($this->posX+21,$this->posY+7);
		$this->showinfo->setSize(10, 3);
		$this->showinfo->setValign("top");
		$this->showinfo->setHalign("right");
		$this->showinfo->setTextSize(1);
	}

	function onLoad() {



	}

	function onDraw() {
		$storage = Storage::getInstance();
		$time = new Time();

		$this->clearComponents();

		$this->addComponent($this->background);

		$this->addComponent($this->tmx);

		//$this->addComponent($this->serverc);
		//$minRank = intval($storage->server->ladderServerLimitMin)/1000;
		//$maxRank = intval($storage->server->ladderServerLimitMax)/1000;
		//$ladderLabel = $minRank."-".$maxRank."k";

                $this->showinfo->setText($this->textColor.'Click for info');
		$this->addComponent($this->showinfo);


		$this->nowPlaying->setText($this->textColor."Now Playing on");
		$this->addComponent($this->nowPlaying);


		$this->trackname->setText($this->textColor.$storage->currentChallenge->name);
		$this->addComponent($this->trackname);

		$this->trackauthor->setText($this->textColor.$storage->currentChallenge->author.'$z'.$this->textColor.' ('.$time->fromTM($storage->currentChallenge->authorTime).')');
		$this->addComponent($this->trackauthor);



	}

	function onResize()
	{

	}

	function setCountry($text)
	{
		$this->serverCountry = $text;
		$this->serverc->setImage(Core::$countries.'/'.$this->serverCountry.".dds", true);
	}

	function onTmxClick($login)
	{
		call_user_func($this->callBack, $login);
		//$this->redraw();
	}

	function destroy()
	{
		unset($this->callBack);
		parent::destroy();
	}

}
?>